package com.daz.test.springwebservice.endpoint;

import com.daz.test.springwebservice.endpoint.example.ExampleRequest;
import com.daz.test.springwebservice.endpoint.example.ExampleResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

@Endpoint
public class ExampleEndpoint {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @PayloadRoot(localPart = "ExampleRequest",
            namespace = "http://springwebservice.daz.com/example")
    public @ResponsePayload
    ExampleResponse example(@RequestPayload ExampleRequest request) {
        ExampleResponse response = new ExampleResponse();
        logInfo(request.toString());
        response.setMessage("Hello, Receive message:" + request.toString());
        return response;
    }

    private void logInfo(String msg) {
        if (logger.isInfoEnabled()) {
            logger.info(msg);
        }
    }
}
